home *** CD-ROM | disk | FTP | other *** search
- {******* demo.pas *******}
-
- unit Demo;
-
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, StdCtrls, Mask, DBCtrls, Menus, PrnMain;
-
- const
- LeftMargin = 0.5;
- RightMargin = 0.5;
- TopMargin = 0.5;
- BottomMargin = 0.5;
-
- type
- TPrintForm = class(TForm)
- Button1: TButton;
- Button2: TButton;
- PixelsPerInch: TPanel;
- PixelsPerPage: TPanel;
- Gutters: TPanel;
- LineHeight: TPanel;
- FontInformation: TPanel;
- LinesInDetailArea: TPanel;
-
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- PrintForm: TPrintForm;
- Prn: TPrintObject;
-
- implementation
-
- {$R *.DFM}
-
- procedure TPrintForm.Button1Click(Sender: TObject);
-
- var
- Buffer: String;
- Code: String[10];
- ECHOCode: String[10];
- HeaderLine: Boolean;
- I: Word;
-
-
- Begin
- { Define the dimensions of the header area. I want the header area
- lightly shaded. If I wanted no shading, the last parameter would be
- 255. }
- with prn do
- begin
- SetHeaderDimensions( 0.25,0.25,8.25,1.25,True,0,225 );
-
- { Define two header lines }
- SetHeaderInformation( 1,0.5,'This is header line number 1',1,'Arial',14,[fsBold] );
- SetHeaderInformation( 2,1.0,DateToStr(Date),1,'Arial',11,[] );
-
- { Define the dimensions of the footer area. I want the footer area
-
- lightly shaded. If I wanted no shading, the last parameter would be
- 255. }
- SetFooterDimensions( 0.25,9.40,8.25,10.20,True,0,225 );
-
- { Define two footer lines }
- SetFooterInformation( 1,9.5,'This is footer line number 1',1,'Arial',14,[fsBold] );
- SetFooterInformation( 2,9.85,'This is footer line number 2',1,'Arial',12,[fsBold] );
-
- { I would like page numbering, right justified on the very bottom of the
- page. }
- SetPageNumberInformation( 10.25,'Page: %d',2,'Arial',9,[fsBold] );
-
-
- { Set the current position to the top of the detail area }
- SetTopOfPage;
-
- { Write three lines, the first left justified, the second centered and
- the third right justified. The first line gets printed two inches
- from the top. The next two lines get printed at the next line from
- the previous line. The '-1' for the first parameter indicates that
- printing should be on the next line. If '-2' is passed as a
- parameter, printing would occur on the current line. }
-
- WriteLine( -1.0,2.0,'This is a line left justified' );
- WriteLineCenter( -1.0,'This is a line centered' );
- WriteLineRight( -1.0,'This is a line right justified' );
-
- { Create five columns. The first parameter is the column number, the
- second parameter is the location in inches from the left and the third
- parameter is the length in inches. }
- CreateColumn( 1,0.25,1.5 );
- CreateColumn( 2,1.80,1.5 );
- CreateColumn( 3,3.35,1.5 );
- CreateColumn( 4,4.90,1.5 );
-
- CreateColumn( 5,6.50,1.5 );
-
- { Start writing column text (left justified) at three inches from the
- top }
- SetYPosition( 3.0 );
- For I := 1 To 10 Do
- Begin
- { The first parameter of 'WriteLineColumn' is the column number and
- the second parameter indicates that printing should occur on the
- current line (in this case, three inches from the top). If the
- second parameter was -1, printing would occur on the next line. }
-
- WriteLineColumn( 1,-2,Format('Column 1, Line %d',[I]) );
- WriteLineColumn( 2,-2,Format('Column 2, Line %d',[I]) );
- WriteLineColumn( 3,-2,Format('Column 3, Line %d',[I]) );
- WriteLineColumn( 4,-2,Format('Column 4, Line %d',[I]) );
- WriteLineColumn( 5,-2,Format('Column 5, Line %d',[I]) );
- { Generate a line feed }
- NextLine;
- End;
-
- { Start writing column text (right justified) at six inches from the
-
- top }
- SetYPosition( 5.0 );
- For I := 1 To 10 Do
- Begin
- WriteLineColumnRight( 1,-2,Format('Column 1, Line %d',[I]) );
- WriteLineColumnRight( 2,-2,Format('Column 2, Line %d',[I]) );
- WriteLineColumnRight( 3,-2,Format('Column 3, Line %d',[I]) );
- WriteLineColumnRight( 4,-2,Format('Column 4, Line %d',[I]) );
- WriteLineColumnRight( 5,-2,Format('Column 5, Line %d',[I]) );
- NextLine;
- End;
-
-
- { Start writing column text (centered) at seven inches from the
- top }
- SetYPosition( 7.0 );
- For I := 1 To 10 Do
- Begin
- WriteLineColumnCenter( 1,-2,Format('Column 1, Line %d',[I]) );
- WriteLineColumnCenter( 2,-2,Format('Column 2, Line %d',[I]) );
- WriteLineColumnCenter( 3,-2,Format('Column 3, Line %d',[I]) );
- WriteLineColumnCenter( 4,-2,Format('Column 4, Line %d',[I]) );
- WriteLineColumnCenter( 5,-2,Format('Column 5, Line %d',[I]) );
-
- NextLine;
- End;
-
- { Start a new page }
- NewPage;
-
- { Change the font information }
- SetFontInformation( 'Courier',20,[fsBold,fsUnderline] );
-
- For I := 1 To 10 Do
- WriteLine( LeftMargin,-1,Format('This is line %d',[I]) );
-
- { Set a tab of .5 inches }
- SetTab( 0.5 );
-
- { Change the font information }
- SetFontInformation( 'Arial',10,[fsItalic] );
- NextLine;
- For I := 1 To 10 Do
- { Since a tab of .5 is set, this text will actually get printed at
-
- 1.0 inches from the left }
- WriteLine( LeftMargin,-1,Format('This is line %d',[I]) );
-
- { Draw some lines of varying thickness }
- DrawLine( 2.5,5.0,6.0,8.5,5 );
- DrawLine( 6.2,5.2,3.0,8.7,20 );
-
- { We're all done. Always call 'Quit' }
- Quit;
- Free;
- Exit;
- end;
- End;
-
- procedure TPrintForm.FormCreate(Sender: TObject);
- var
- X,Y: Word;
- Top,Bottom,Left,Right: Word;
-
-
- Begin
- { Create a TPrintObject }
- Prn := TPrintObject.Create;
- with prn do
- begin
-
- { Must always call 'Start' first thing }
- Start;
-
- { Set left, right, top and bottom margins - in inches }
- SetMargins( LeftMargin,RightMargin,TopMargin,BottomMargin );
-
- { Define what the 'detail' section dimensions will be. The detail section
- is the space between the header and the footer areas. }
- SetDetailTopBottom( 1.4,9.4 );
-
- { Set default information }
-
- SetFontInformation( 'Arial',11,[] );
-
- GetPixelsPerInch( X,Y );
- PixelsPerInch.Caption := Format( 'Pixels Per Inch X: %d Y: %d',[X,Y] );
-
- GetPixelsPerPage( X,Y );
- PixelsPerPage.Caption := Format( 'Pixels Per Page X: %d Y: %d',[X,Y] );
-
- GetGutter( Top,Bottom,Left,Right );
- Gutters.Caption := Format( 'Gutters Top: %d Bottom: %d Left: %d Right: %d',[Top,Bottom,Left,Right] );
-
- LineHeight.Caption := Format( 'Height of Each Line: %d',[GetLineHeightPixels] );
-
-
- FontInformation.Caption := Format( 'Font Name: %s Font Size: %d',[GetFontName,GetFontSize] );
-
- LinesInDetailArea.Caption := Format( 'Lines in Detail Area: %d',[GetLinesInDetailArea] );
- end; {with}
- End;
-
- procedure TPrintForm.Button2Click(Sender: TObject);
-
- Begin
- Close;
- Halt;
- End;
-
- end.
-
-